import org.gradle.api.Project
import org.gradle.kotlin.dsl.*

/**
 * @author xiangliyou
 * @email xiangliyou1814@mail.yneusoft.com
 * @date 2019-03-05 19:03
 *
 */
//项目是否是调试模式
const val DEBUG = false

/**
 * 配置在当前项目加上 Kotlin 'stdlib' 依赖
 */
fun Project.kotlinProject() {
    dependencies {
        "implementation"(kotlin("stdlib-jdk8"))
        "implementation"(kotlin("reflect"))
    }
}

/**
 * web 项目需要的依赖
 */
fun Project.webProject() {
    kotlinProject()
    configurations {
        // 项目不使用 tomcat 和 cglib
        "implementation" {
            this.exclude(module = "spring-boot-starter-tomcat")
            this.exclude(module = "cglib")
        }
    }

    dependencies {
        //framework-core
        "implementation"(project(":cloud-mall-framework:cloud-mall-framework-core"))

        //jackson
        "implementation"("com.fasterxml.jackson.module:jackson-module-kotlin")
        //web-starter
        "implementation"("org.springframework.boot:spring-boot-starter-web")
        //使用undertow
        "implementation"("org.springframework.boot:spring-boot-starter-undertow")
        //apo
        "implementation"("org.springframework.boot:spring-boot-starter-aop")

        "implementation"("org.springframework.boot:spring-boot-starter-test")
    }
}

/**
 * 提供服务接口的项目
 */
fun Project.serviceProject() {
    webProject()

    dependencies {
        //eureka 注册中心
//        "implementation"("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client")
        // 引入熔断器
        "implementation"("org.springframework.cloud:spring-cloud-starter-netflix-hystrix")
        //使用配置中心客户端
        "implementation"("org.springframework.cloud:spring-cloud-config-client")
        // consul 客户端
        "implementation"("org.springframework.cloud:spring-cloud-starter-consul-discovery")
        // actuator 服务健康监控
        "implementation"("org.springframework.boot:spring-boot-starter-actuator")
        //feign 网络请求
        "implementation"("org.springframework.cloud:spring-cloud-starter-openfeign")
    }
}

/**
 * 需要与数据库交互的项目
 */
fun Project.databaseProject() {
    dependencies {
        //redis
        "implementation"("org.springframework.boot:spring-boot-starter-data-redis")
        //缓存
        "implementation"("org.springframework.boot:spring-boot-starter-cache")
        //jpa
        "implementation"("org.springframework.boot:spring-boot-starter-data-jpa")
        //数据库驱动
        "runtimeOnly"("mysql:mysql-connector-java")
    }
}

/**
 * 开放服务出来的项目
 */
fun Project.openProject() {
    kotlinProject()
    dependencies {
        //feign 网络请求
        "implementation"("org.springframework.cloud:spring-cloud-starter-openfeign")
        //jackson
        "implementation"("com.fasterxml.jackson.module:jackson-module-kotlin")
    }
}